package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.User;
import service.UserService;
import service.impl.UserServiceImpl;

public class RegisterByEmailServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	UserService userService = new UserServiceImpl();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		String login_name = request.getParameter("login_name");
		String email = request.getParameter("email");
		String password = request.getParameter("password");
		
		User user = new User();
		user.setLoginName(login_name);
		user.setEmail(email);
		user.setPassword(password);
		user.setStatus(0);
		user.setUsername(login_name);
		
		boolean result = userService.registerByEmail(user);
		
		if (result) {
			response.getWriter().print("注册成功！用户名："+login_name+", 密码："+password+",请登录邮箱进行验证(5分钟有效)："+email);
		}else {
			response.getWriter().print("注册失败！");
		}
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
